﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Net;
using System.Text;
using System.Windows.Forms;

namespace FastAccess
{
    public partial class ProxyAddForm : Form
    {
        public ProxyAddForm()
        {
            InitializeComponent();
        }

        public ProxyDB Db
        {
            get;
            set;
        }

        private void button1_Click(object sender, EventArgs e)
        {
            ProxyDB.ProxyLsRow row = Db.ProxyLs.NewProxyLsRow();
            row.IP = IP.Text;
            row.Port = Port.Text;
            if (AnymouseProxy.Checked)
            {
                row.Password = "N/A";
                row.UserName = "Anymouse";
            }
            else
            {
                row.UserName = UserName.Text;
                row.Password = Password.Text;
            }
            if (Helper.AccessByProxy(row, Settings.TestUrl))
            {
                try
                {
                    Db.ProxyLs.AddProxyLsRow(row);
                }
                catch (System.Data.ConstraintException ex)
                {
                    MessageBox.Show("已经存在此代理");
                }
            }
            else
            {
                MessageBox.Show("此代理无效");
            }
            this.Close();
        }
    }
}
